package br.fatec.servico;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class UsuarioDAO implements IUsuarioDAO {
	private static final String consultaUsuario = "SELECT *  FROM usuario ";

	

	private Connection conecta() {
		Connection con = null;
		String msg;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("JDBC driver carregado");
			con = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/controledeacesso", "root", "");
		} catch (ClassNotFoundException e) {
			System.out.println(e.toString());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			msg = e.getMessage();
			System.out.println(msg);
		}
		return con;
	}

	//
	public ResultSet consultaTodos() {
		String msg = "";
		ResultSet rs = null;
		try {
			Statement s = conecta().createStatement();
			rs = s.executeQuery(consultaUsuario);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			msg = e.getMessage();
			System.out.println(msg);
		}

		return rs;
	}
}
